<?php
use yii\helpers\Html;
use yii\helpers\Url;
/* @var $this yii\web\View */
$this->title = '实名认证';
$session = yii::$app->session;
$session->open();
?>
<section id="body_h">
		<div class='modular13 modular17'>
			<div class="modular12-con1from">
				<p class="modular12-con1ts2">您必须填写您的真实姓名和身份证号码，虚假的身份信息，是不能通过验证的。</p>
				<form id="submitall" action="" method="post">
					<input type='hidden' name='front' value='' />
					<input type='hidden' name='back' value='' />
					<p class="oneelement greenborder"><input name="realname" class="changeelement" placeholder="请输入真实姓名" type="text"></p>
					<p class="oneelement greenborder"><input name="idcard" class="changeelement" placeholder="请输入身份证号" type="text"></p>
				</form>
				<form  id="uploadIDCardFront" action="" method="post" enctype="multipart/form-data">
					<div class="twoelement">
						<span class="changeelement greenborder border-r5 colorb">&nbsp;&nbsp;&nbsp;&nbsp;身份证文件（正面）</span>
						<p class="fixedelement2">
							<span>上传</span>
							<input type="file" name="stream" id="file1" />
						</p>
					</div>
				</form>
				<form  id="uploadIDCardBack" action="" method="post" enctype="multipart/form-data">
					<div class="twoelement">
						<span class="changeelement greenborder border-r5 colorb">&nbsp;&nbsp;&nbsp;&nbsp;身份证文件（反面）</span>
						<p class="fixedelement2">
							<span>上传</span>
							<input type="file" name="stream" id="file2" />
						</p>
					</div>
					<div class="modular12-con1ts3">
						<p><img src="<?= Yii::getAlias('@web') . '/' ?>images/idcordzm.jpg" alt=""></p>
						<p><img src="<?= Yii::getAlias('@web') . '/' ?>images/idcordfm.jpg" alt=""></p>
					</div>
				</form>
					<p class="mould-2bot form-ok"><input class="form-okbtn b-f" type="submit" value="提交"></p>
			</div>
		</div>
		<div class="modular2">
			<p>如有任何疑问，请拨打客服电话 <span class="bluecolor">4006-900-880</span> <br>工作时间：09：00-17：30</p>
		</div>
		<div class="footer-h"></div>
</section>
	<section id="footer">
		<ul class="footer-nav clearfix">
		    <li class="current-bot">
		        <a href="<?= Url::to('main');?>">
		            <img src="<?= Yii::getAlias('@web') . '/' ?>images/footer1-on.png" alt="">
		            首页
		        </a>
		    </li>
		    <li>
		        <a href="<?= Url::to('member');?>">
		            <img src="<?= Yii::getAlias('@web') . '/' ?>images/footer2.png" alt="">
		            我的账户
		        </a>
		    </li>
		    <li>
		        <a href="<?= Url::to(['company/about']);?>">
		            <img src="<?= Yii::getAlias('@web') . '/' ?>images/footer3.png" alt="">
		            关于我们
		        </a>
		    </li>
		</ul>
	</section>
	<p id="tip-error"><span>表单验证错误信息</span></p>
<script type="text/javascript">
		$(function(){
				$("#uploadIDCardFront").change(function(){
					var formData = new FormData($( "#uploadIDCardFront" )[0]);  
				     $.ajax({  
				          url: '<?= PANDA_SERVER;?>/uploadIDCardFront?sKey='+ '<?= $session->get('sKey');?>' +'&tokenId='+ '<?= $session->get('tokenid')?>' ,  
				          type: 'POST',  
				          data: formData,  
				          async: false,  
				          cache: false,  
				          contentType: false,  
				          processData: false,  
				          success: function (returndata) {
					          if(returndata.status==0)
					          {
									$('#tip-error span').html('上传成功！');
							        $('#tip-error').show();
							        setTimeout(function(){$('#tip-error').fadeOut(500);},1600);
									$("input[name='front']").val(returndata.obj);
						      }
					          else
					          {
					        	  	$('#tip-error span').html(returndata.msg);
							        $('#tip-error').show();
							        setTimeout(function(){$('#tip-error').fadeOut(500);},1600);
						      }
				          },  
				          error: function (returndata) {
					        	  	$('#tip-error span').html(returndata.msg);
							        $('#tip-error').show();
							        setTimeout(function(){$('#tip-error').fadeOut(500);},1600); 
				          }
				     }); 
				});
					$("#uploadIDCardBack").change(function(){
						var formData = new FormData($( "#uploadIDCardBack" )[0]);
					     $.ajax({
					          url: '<?= PANDA_SERVER;?>/uploadIDCardBack?sKey='+ '<?= $session->get('sKey');?>' +'&tokenId='+ '<?= $session->get('tokenid')?>' ,  
					          type: 'POST',  
					          data: formData,  
					          async: false,  
					          cache: false,  
					          contentType: false,  
					          processData: false,  
					          success: function (returndata) {
						          if(returndata.status==0)
						          {
										$('#tip-error span').html('上传成功！');
								        $('#tip-error').show();
								        setTimeout(function(){$('#tip-error').fadeOut(500);},1600);
										$("input[name='back']").val(returndata.obj);
							      }
						          else
						          {
						        	  	$('#tip-error span').html(returndata.msg);
								        $('#tip-error').show();
								        setTimeout(function(){$('#tip-error').fadeOut(500);},1600);
							      }
					          },  
					          error: function (returndata) {
						        	  	$('#tip-error span').html(returndata.msg);
								        $('#tip-error').show();
								        setTimeout(function(){$('#tip-error').fadeOut(500);},1600); 
					          }
					     }); 
					});
					
				$(".form-okbtn").click(function(event){
						var file1 = $("#file1").val();
						var file2 = $("#file2").val();
			            var front = $("input[name='front']").val();
			            var back = $("input[name='back']").val();
			            var realname = $("input[name='realname']").val();
			            var idcard = $("input[name='idcard']").val();
			            var sKey = '<?= $session->get('sKey');?>';
			            var reg=/^[1-9]{1}[0-9]{14}$|^[1-9]{1}[0-9]{16}([0-9]|[xX])$/;
			        	if(realname == false){
							$('#tip-error span').html('真实姓名不能为空');
					        $('#tip-error').show();
					        setTimeout(function(){$('#tip-error').fadeOut(500);},1600);
			        		$("input[name='realname']").focus();
			        	}else if(idcard==false){
			        		$('#tip-error span').html('身份证号不能为空');
					        $('#tip-error').show();
					        setTimeout(function(){$('#tip-error').fadeOut(500);},1600);
			        		$("input[name='idcard']").focus();
						}else if(!reg.test(idcard)){
			        		$('#tip-error span').html('身份证格式不正确');
					        $('#tip-error').show();
					        setTimeout(function(){$('#tip-error').fadeOut(500);},1600);
			        		$("input[name='idcard']").focus();
						}else if(file1 == false){
			        		$('#tip-error span').html('请上传身份证正面');
					        $('#tip-error').show();
					        setTimeout(function(){$('#tip-error').fadeOut(500);},1600);
						}else if(file2 == false){
			        		$('#tip-error span').html('请上传身份证反面');
					        $('#tip-error').show();
					        setTimeout(function(){$('#tip-error').fadeOut(500);},1600);
						}else
						{
							$.post(
									'<?= Url::to(['authentication/doauthentication']);?>',
									{idcard:idcard,realname:realname,front:front,back:back,sKey:sKey,'_csrf':'<?= yii::$app->request->getCsrfToken();?>'},
									function(data)
									{
										var obj = eval("("+data+")");
										if(obj.status == 0)
										{
											$('#tip-error span').html('提交成功！');
									        $('#tip-error').show();
									        setTimeout(function(){$('#tip-error').fadeOut(500);},1600);
									        location.href='<?= Url::to(['site/member']);?>';
										}
										else
										{
											$('#tip-error span').html(obj.msg);
									        $('#tip-error').show();
									        setTimeout(function(){$('#tip-error').fadeOut(500);},1600);
										}
									});
						}
				});
		});
		
	</script>